<!-- BEGIN HEAD -->
<%- include ../indexHeader %>
<!-- END HEAD -->
<div class="container">

    <div class="blog-detail">
        <div id="puinfo">
            <div id="puinfobody">
                <h3><%= detailInfo.title%>
                    <%if(detailInfo.isTop == 1){%>
                    <span class="yy-icon yy-tjhs" title="列表推荐"></span>
                    <%}else{%>
                    <span class="yy-icon yy-tj" title="列表推荐"></span>
                    <%}%>
                </h3>
                <p>作者：<a href="###" target="_blank"><%= detailInfo.author%></a>
                    &nbsp;&nbsp;发布日期：<span class="item-time"><i class="fa fa-clock-o"></i><a><%=myDateFormat(detailInfo.date)%></a></span>
                </p>
            </div>
            <span class="pull-right" id="prenqi">
                <span>人气</span><a id="clNum"><%= detailInfo.clickNum%></a>
            </span>
        </div>
        <%if(detailInfo.from == '2'){%>
        <div class="col-md-12">
            <div class="row">
                <p class="plicense">本教程为网络转载，版权为作者本人所有。分享时请注明，谢谢</p>
            </div>
        </div>
        <%}%>
        <div class="col-md-12 col-sm-12 col-xs-12 content">
            <div class="col-md-2 col-sm-2">&nbsp;</div>
            <div class="col-md-8 col-sm-8 col-xs-12 projectpostbody">
                <%- detailInfo.comments%>
            </div>
            <div class="col-md-2 col-sm-2"></div>

        </div>
        <div class="row">
            <div class="col-md-12 col-sm-12 col-xs-12 blog-footer">
                <div class="qrCode">
                    <img class="pull-left" width="87" height="87" alt="手机预览此网页" src="/content/qrImg/show?detailLink=http://<%=myDomain%>/details/<%=detailInfo._id%>.html"/>
                    <!--<img src="/stylesheets/front/images/30580.png" alt="手机预览此网页" class="pull-left"/>-->
                    <span>
                        <h2>扫一扫</h2>
                        <small>手机预览此网页</small>
                    </span>
                </div>
                <div class="ilike">
                    <a class="text-center" href="###" onclick="updateMylike('<%=detailInfo._id%>','<%=detailInfo.likeUserIds%>')"><span class="glyphicon glyphicon-heart"></span>&nbsp;喜欢(<span class="likecount"><%=detailInfo.likeNum%></span>)</a>
                </div>
                <div class="likePerson" ng-controller="likePerson">
                    <img src="<%=staticFilePath%>/stylesheets/front/images/like.gif" class="likeImg" alt="谁喜欢过"/>
                    <span class="list">
                        <ul>

                            <li ng-repeat="umember in memberList"><a href="###"><img src="{{umember.logo}}" class="img-responsive" alt="logo"/></a></li>

                        </ul>
                    </span>
                    <div class="clearfix"></div>
                </div>
                <div class="share-detail">
                    <div class="pctiem pull-left" id="ptags">
                        <span class="yy-icon yy-soi2"></span>标签&nbsp;&nbsp;
                        <%var taglist = [];taglist = (detailInfo.tags).split(',')%>
                        <%for(var i=0;i<taglist.length;i++){%>
                        <a target="_blank" href="###"><%=taglist[i]%></a>&nbsp;
                        <%}%>
                    </div>
                    <div class="share-btn">
                        <a class="pvshare yy-icon yy-ssina" title="分享到新浪微博" target="_blank" href="http://service.weibo.com/share/share.php?title=<%=detailInfo.discription%>&url=http://<%=myDomain%>/details/<%=detailInfo._id%>.html&source=<%=siteConfig.title%>&appkey=902932546&pic=<%=updateFilePath%><%=detailInfo.sImg%>"></a>&nbsp;
                        <a class="pvshare yy-icon yy-sqq" target="_blank" href="#"></a>&nbsp;
                        <script type="text/javascript">
                            (function(){
                                var p = {
                                    url:location.href,
                                    showcount:'1',/*是否显示分享总数,显示：'1'，不显示：'0' */
                                    desc:'',/*默认分享理由(可选)*/
                                    summary:'<%=detailInfo.discription%>',/*分享摘要(可选)*/
                                    title:'<%=siteConfig.title%>',/*分享标题(可选)*/
                                    site:'<%=siteConfig.title%>',/*分享来源 如：腾讯网(可选)*/
                                    pics:'<%=updateFilePath%><%=detailInfo.sImg%>', /*分享图片的路径(可选)*/
                                    style:'203',
                                    width:98,
                                    height:22
                                };
                                var s = [];
                                for(var i in p){
                                    s.push(i + '=' + encodeURIComponent(p[i]||''));
                                }
                                document.write(['<a version="1.0" class="pvshare yy-icon yy-qqzone" href="http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?',s.join('&'),'" target="_blank"></a>&nbsp;'].join(''));
                            })();
                        </script>
                        <script src="http://qzonestyle.gtimg.cn/qzone/app/qzlike/qzopensl.js#jsdate=20111201" charset="utf-8"></script>
                        <!--<a class="pvshare yy-icon yy-qqzone" target="_blank" href="#"></a>&nbsp;-->
                        <a class="pvshare yy-icon yy-sfb" target="_blank" href="http://www.facebook.com/sharer.php?u==http://<%=myDomain%>/details/<%=detailInfo._id%>.html&pic=<%=updateFilePath%><%=detailInfo.sImg%>"></a>
                    </div>
                </div>
            </div>
        </div>
        <div class="clearfix"></div>
    </div>
    <div class="maybeLike">

        <div class="col-md-12">
            <h3>猜你喜欢</h3>
            <ul>
                <%randomList.forEach(function(item){%>
                <li class="col-md-3 col-sm-6 col-xs-6"><a href="/details/<%= item._id%>.html"><img class="img-responsive" src="<%=updateFilePath%><%=item.sImg%>" title="<%=item.title%>"/></a></li>
                <%})%>
            </ul>
        </div>
        <div class="clearfix"></div>

    </div>

    <div class="detail-Comments" ng-controller="uMessage">
        <div class="col-md-12">
            <% if(!logined){ %>
            <div class="notice">
                <p>只有登录之后才可以评论，请点击<a href="###" data-toggle="modal" data-target="#uLoginModal">这里</a>进行登录</p>
            </div>
            <div class="clear"></div>

            <div class="loginState" loginState = "0"></div>
            <%}else{%>
            <input type="hidden" value="<%=userInfo._id%>" id="uid"/>
            <input type="hidden" value="<%=userInfo.userName%>" id="uName"/>
            <input type="hidden" value="<%=userInfo.logo%>" id="ulogo"/>
            <div class="msg-area">
                <div id="cmhead" class="loginState" loginState = "1">
                    <p>帐号：<a target="_blank" href="###"><%=userInfo.userName%></a>
                        <a id="cm-s1" href="###">退出</a>
                        <span class="submitwarning" style="display: none;">内容不能为空</span>
                    </p>
                    <div id="cmhbody">
                        <a title="doramart" class="m-logo" target="_blank" href="###">
                            <img width="50" height="50" src="<%=userInfo.logo%>">
                        </a>
                        <div id="postcm">
                            <form role="form" class="form-horizontal" name="msgForm" ng-submit="sentMsgForm(msgForm.$valid)" novalidate>
                                <button class="btn btn-gray1 submitbtn"  ng-disabled="msgForm.$invalid">发表评论</button>
                            <div class="textbg">
                                <textarea id="msgTextArea" ng-model="msgFormData.content" required class="inputnone"></textarea>
                            </div>
                            <div class="clear"></div>
                            </form>
                        </div>
                    </div>

                </div>
            </div>
            <%}%>
            <p id="cm-s2">全部评论: <span><%=detailInfo.commentNum%></span>条</p>
            <div data-uid="34625" data-id="26403" class="cmitem" ng-repeat="msg in messageList">
                <a target="_blank" class="m-logo" title="bErtoN" href="###">
                    <img width="50" height="50" src="{{msg.ulogo}}">
                </a>
                <div class="cmitembody" id="msg_{{msg._id}}">
                    <p class="cm-s4">
                        <a target="_blank" href="###">{{msg.uName}}</a>
                        <span>{{msg.date | date:"yyyy-MM-dd" }}</span>
                        <span class="cpraise"  ng-class="{true: 'hasPraise'}[msg.hasPraise]" ng-click="updatePraise(msg._id)">赞(<span class="num">{{msg.praiseNum}}</span>)</span>
                    </p>
                    <p class="cm-s6">
                        {{msg.content}}
                        <a class="cm-s5" ng-click="replyMsg(msg.uName,msg.uid)">[回复]</a>
                    </p>
                </div>
            </div>
        </div>
        <div class="clearfix"></div>
    </div>


</div> <!-- /container -->

<!-- BEGIN FOOTER -->

<%- include ../footer %>

<!-- END FOOTER -->

<script type="text/javascript">
    $(function() {
//        App.init();
        var cateId = '<%=detailInfo.category%>';
        var myParentCateID = '<%=detailInfo.sortPath%>';
        var detailID = '<%=detailInfo._id%>';
        var oldClickNum = '<%=detailInfo.clickNum%>';


//        更新访问量
        updateClickNum(detailID,oldClickNum);
//        喜欢文章初始化
        initLikeNum('<%=detailInfo.likeUserIds%>');

//        模态窗口初始化
//        $('.modal').on('show.bs.modal', centerModals);
//        $(window).on('resize', centerModals);
    });
</script>

<script>
    doraApp.controller('likePerson',function($scope,$http){
        $scope.memberList = {};
        //                初始化喜欢人员列表
        getLikeMembers($scope,$http,'<%=detailInfo.likeUserIds%>');

    });
    doraApp.controller('uMessage',function($scope,$http){

                $scope.msgFormData = {};
                var detailId = '<%=detailInfo._id%>';

                $scope.msgFormData.contentId = '<%=detailInfo._id%>';
                $scope.msgFormData.contentTitle = '<%=detailInfo.title%>';
                $scope.msgFormData.commentNum = '<%=detailInfo.commentNum%>';

//                初始化留言信息
                getMsgData($scope,$http,detailId);

                $scope.sentMsgForm = function(isValid){
//                    获取登录状态
//                    var loginState = $('.uMessage').find('.userHeader').attr('imgState');
//                    if(loginState == '0'){
//                        $('#userLoginDialog').modal('show');
//                    }else{

                        $scope.msgFormData.uName = $('#uName').val();
                        $scope.msgFormData.uid =  $('#uid').val();
                        $scope.msgFormData.ulogo = $('#ulogo').val();

                        $http({
                            method  : 'POST',
                            url     : '/users/message/sent',
                            data    : $.param($scope.msgFormData),  // pass in data as strings
                            headers : { 'Content-Type': 'application/x-www-form-urlencoded' }  // set the headers so angular passing info as form data (not request payload)
                        })
                        .success(function(data) {
                            if(data === "success"){
                                getMsgData($scope,$http,detailId);
                            }else{
                                alert("未知异常，请稍后重试");
                            }
                        });
//                    }

                };

//                回复留言
                $scope.replyMsg = function(uName,uid){
                   var loginState =  $('.loginState').attr('loginState');
                    if(loginState == '0'){
                        $('#uLoginModal').modal('show');
                    }else{

                        $('#msgTextArea').focus();
                        $scope.msgFormData.content = "@"+uName+" ";
                        $scope.msgFormData.relationUid = uid;

                    }
                };


//                点赞功能
                $scope.updatePraise = function(msgId){
                    updateMyPraise(msgId);
                }
            });



            function getMsgData($scope,$http,detailId){
                $scope.messageList = {};
                $('.msgList').hide();
                $http.get('/users/message/getlist?contentId='+detailId).success(function(result){
                    if(result.length > 0){
                        $('.msgList').show();
//                        初始化点赞数据
                        var loginState =  $('.loginState').attr('loginState');
                        if(loginState == '1'){
                            for(var i=0;i<result.length;i++) {
                                var msgObj = result[i];
                                var msgUids = msgObj.praiseMembers;

                                if(msgUids){
                                    var idsArray = msgUids.split(',');
                                    for (var j = 0; j < idsArray.length; j++) {
                                        if (idsArray[j] == $('#uid').val()) {
                                            msgObj.hasPraise = true;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        $scope.messageList = result;

        //                清空留言信息
                        $scope.msgFormData.content = "";
                    }
                })
            }

            function getLikeMembers($scope,$http,likeUserIds){

                $http.get('/users/likeMembers/list?likeUserIds='+likeUserIds).success(function(result){

                    if(result.ulist.length > 0){
                        var dataList = [];
                        for(var i=0;i<result.ulist.length;i++){
                            var item = result.ulist[i][0];
                            dataList.push(item);
                        }
                        $scope.memberList = dataList;

                    }
                })
            }
</script>
<!-- END PAGE LEVEL JAVASCRIPTS -->
</body>
<!-- END BODY -->
</html>
